module ActionController
  class AbstractRequest
    # override to fix certain ambiguities with IIS and Fast CGI
    def request_uri
		if uri = env['REQUEST_URI']        
			(%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri # Remove domain, which webrick puts into the request_uri.
		else # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
      
		# remove the script file name (dispatch.fcgi/dispatch.rb) from the URI
        uri = env['PATH_INFO'] 
        uri = uri.sub("#{env['SCRIPT_NAME']}", "") unless env['SCRIPT_NAME'].nil?
	
		# replace the isapi rewrite query string with the original path and query (opnq)
		unless( opnq = env["QUERY_STRING"]).nil? || opnq.empty?
			env["QUERY_STRING"] = opnq.sub("?","&") # overwrite the invalid query string
			uri << opnq.sub("opnq=","")
		end
		
		uri
      end
    end
  end
end